package redis

import (
	"github.com/go-redis/redis"
	"github.com/spf13/viper"
	"go.uber.org/zap"
)

var Rdb *redis.Client

func InitRedis() (err error) {
	Rdb = redis.NewClient(&redis.Options{
		Addr:     viper.GetString("redis.host") + ":" + viper.GetString("redis.port"),
		Password: viper.GetString("redis.password"),
		DB:       viper.GetInt("redis.db"),
		PoolSize: viper.GetInt("redis.pool_size"),
	})
	_, err = Rdb.Ping().Result()
	if err != nil {
		zap.L().Error("redis connect error", zap.Error(err))
		return err
	}
	return nil
}
